<template>
  <div class="header-bar">
    <sider-trigger :collapsed="collapsed" icon="md-menu" @on-change="handleCollpasedChange"></sider-trigger>
    <custom-bread-crumb show-icon style="margin-left: 30px;" :list="breadCrumbList"></custom-bread-crumb>
    <div class="custom-content-con">
      <slot></slot>
    </div>
  </div>
</template>
<script>
import siderTrigger from './sider-trigger'
import customBreadCrumb from './custom-bread-crumb'
export default {
  name: 'headerBar',
  components: {
    siderTrigger,
    customBreadCrumb
  },
  props: {
    collapsed: Boolean,
    menuList: Array
  },
  computed: {
    breadCrumbList () {
      const { name } = this.$route;
      let breadlist = [{ icon: 'md-home', path: 'home', name: 'Home' }];
      this.menuList.forEach(item => {
        if (item.childrens.length > 0) {
          item.childrens.forEach(sub => {
            if (sub.path === name) {
              breadlist.push({ name: item.header }, { name: sub.name });
            }
          });
        }
      });
      return breadlist;
    }
  },
  methods: {
    handleCollpasedChange (state) {
      this.$emit('on-coll-change', state)
    }
  }
}
</script>

<style lang="scss">
@import './header-bar.scss';
</style>
